package com.easemob.chat.core;

import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import com.easemob.b.a;
import com.easemob.chat.EMChatManager;
import com.easemob.chat.StartServiceReceiver;
import com.easemob.util.EMLog;
import com.easemob.util.NetUtils;
import org.jivesoftware.smack.XMPPConnection;

public class HeartBeatReceiver extends BroadcastReceiver
{
  private static final String TAG = "ping";
  private long previousTime = System.currentTimeMillis();
  static t pingPacket = new t();
  private XmppConnectionManager conManager = null;

  public HeartBeatReceiver(XmppConnectionManager paramXmppConnectionManager)
  {
    this.conManager = paramXmppConnectionManager;
  }

  public void onReceive(Context paramContext, Intent paramIntent)
  {
    this.previousTime = System.currentTimeMillis();
    EMLog.d("ping", "has network connection:" + NetUtils.hasNetwork(paramContext) + " has data conn:" + NetUtils.hasDataConnection(paramContext) + "isConnected to easemob server:" + EMChatManager.getInstance().isConnected());
    if ((this.conManager != null) && (this.conManager.isConnected()) && (this.conManager.getConnection() != null))
    {
      try
      {
        EMLog.d("ping", "send heartbeat");
        this.conManager.getConnection().sendPacket(pingPacket);
      }
      catch (Exception localException1)
      {
        EMLog.e("ping", localException1.toString());
      }
    }
    else
    {
      EMLog.d("ping", "....no connection to server");
      try
      {
        if (!NetUtils.hasDataConnection(paramContext))
          return;
        EMLog.d("ping", "... try to reconnect");
      }
      catch (Exception localException2)
      {
        localException2.printStackTrace();
      }
    }
    a.d();
    StartServiceReceiver.schduleNextHeartbeat(paramContext);
  }
}

/* Location:           D:\hygieia\userclient\common\libs\easemobchat_2.1.8.jar
 * Qualified Name:     com.easemob.chat.core.HeartBeatReceiver
 * JD-Core Version:    0.6.1
 */